package com.seata.demo.common.res;

import java.io.Serializable;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* @comments
* @author  zg
* @date 2021年2月9日
*/
@AllArgsConstructor 
@NoArgsConstructor
@Data
public class Resp <T> implements Serializable{
    private static final long serialVersionUID = 1L;

    /** 0：成功 */
    private int code = 0;
    
    private String msg;
    
    //private Object data;
    private T data;
    
    public Resp(int code) {
        this.code = code;
    }
    
    public Resp(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    
    public Resp(int code, T data) {
        this.code = code;
        this.data = data;
    }

    /** 成功 */
    public static<T> Resp<T> success(T data) {
        return new Resp<T>(0, data);
    }
    
    /** 成功 */
    public static<T> Resp<T> success() {
        return new Resp<T>(0);
    }
    
    /** 失败 */
    public static<T> Resp<T> failure() {
        return new Resp<T>(-1);
    }
    
    public static<T> Resp<T> failure(String msg) {
        return new Resp<T>(-1, msg);
    }
    
    /** 失败 */
    public static<T> Resp<T> error() {
        return new Resp<T>(-1);
    }
    
    public static<T> Resp<T> error(String msg) {
        return new Resp<T>(-1, msg);
    }
}
